package com.iwhalecloud.bss.kite.cucc.spec.impl.query;

import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.cucc.client.api.goods.IGoodsService;
import com.iwhalecloud.bss.kite.cucc.dataservice.cache.CuccOfferOriginalInfoCache;
import com.iwhalecloud.bss.kite.cucc.spec.impl.transfer.GoodsInfoTransfer;
import com.iwhalecloud.bss.kite.dataservice.api.IQueryOfferRelService;
import com.iwhalecloud.bss.kite.dataservice.entity.fee.OfferFeeDiscntShowRule;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.Offer;
import com.iwhalecloud.bss.kite.dataservice.entity.spec.OfferRelInfo;
import com.iwhalecloud.bss.kite.dataservice.mapper.spec.OfferRelMapper;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class OfferRelQueryService implements IQueryOfferRelService {

    @Autowired
    private IGoodsService goodsService;

	@Override
	public List<OfferRelInfo> listOfferRelsByOfferId(String offerId) {
	    Map repMap = CuccOfferOriginalInfoCache.get(offerId);
	    if (KiteMapUtils.isEmpty(repMap)) {
	        repMap = goodsService.queryGoodsByOfferId(offerId);
	    }
        List<OfferRelInfo> offerRelInfos = GoodsInfoTransfer.packageSingleDetail(repMap);
        return offerRelInfos;
	}

    @Override
    public List<OfferFeeDiscntShowRule> listOfferFeeDiscntShowRule(String offerId) {
        Map repMap = CuccOfferOriginalInfoCache.get(offerId);
        if (KiteMapUtils.isEmpty(repMap)) {
            repMap = goodsService.queryGoodsByOfferId(offerId);
        }
        List<OfferFeeDiscntShowRule> offerRelInfos = GoodsInfoTransfer.listOfferFeeDiscntShowRule(repMap);
        return offerRelInfos;
    }
	@Override
	public List<OfferRelInfo> listOfferRels(String offerId, String prodId, String rstrType, String offerType) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listOfferRels(offerId, prodId, rstrType, offerType);
	}

	@Override
	public List<OfferRelInfo> listAOfferRelsByOfferId(String offerId, String relType) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        List<OfferRelInfo> offerRelInfos = offerRelMapper.listAOfferRelsByOfferId(offerId, relType);
        return offerRelInfos;
	}

	@Override
	public List<OfferRelInfo> listZOfferRelsByOfferId(String offerId, String relType) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        List<OfferRelInfo> offerRelInfos = offerRelMapper.listZOfferRelsByOfferId(offerId, relType);
        return offerRelInfos;
	}

	@Override
	public List<OfferRelInfo> listMutexOfferRels(String offerId) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listMutexOfferRels(offerId);
	}

	@Override
	public List<OfferRelInfo> listMutexOfferRelExits(String offerId) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listMutexOfferRelExits(offerId);
	}

	@Override
	public int hasMutexOfferRel(String aOfferId, String zOfferId) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.hasMutexOfferRel(aOfferId, zOfferId);
	}

	@Override
	public List<OfferRelInfo> listRelyOnOfferRels(String offerId) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listRelyOnOfferRels(offerId);
	}

	@Override
	public List<OfferRelInfo> listAdditionalOffersByOfferName(String offerId, String roleId, String offerName) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listAdditionalOffersByOfferName(offerId, roleId, offerName);
	}

	@Override
	public List<Offer> listAdditionalOffersByRoleId(String offerId, String roleId) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listAdditionalOffersByRoleId(offerId, roleId);
	}


	@Override
	public List<OfferRelInfo> listPhoneAdditionalOffer(String offerId, String objId, String offerName) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        List<OfferRelInfo> offerRelInfos = offerRelMapper.listPhoneAdditionalOffer(offerId, objId, offerName, null);
        return offerRelInfos;
	}

	@Override
	public List<OfferRelInfo> listBaseOfferAdditionalOffer(String offerId, String objId, String offerName) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listBaseOfferAdditionalOffer(offerId, objId, offerName, null);
	}

	@Override
	public List<OfferRelInfo> listRelByProdAdditionLimt(String offerId, String relType, String rstrType,
			String offerType) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listRelByProdAdditionLimt(offerId, relType, rstrType, offerType);
	}

	@Override
	public List<OfferRelInfo> listAdditionalOffersByLabel(String offerId, String labelId, String offerType) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        return offerRelMapper.listAdditionalOffersByLabel(offerId, labelId, offerType);
	}

	@Override
	public List<OfferRelInfo> listMainOfferAdditionalOffer(String offerId, String roleId, String objId,
			String offerName) {
		OfferRelMapper offerRelMapper = SpringUtil.getBean(OfferRelMapper.class);
        List<OfferRelInfo> offerRelInfos = offerRelMapper.listMainOfferAdditionalOffer(offerId, roleId, objId, offerName, null);
        return offerRelInfos;
	}

}
